﻿using System.Data.Entity.ModelConfiguration;

namespace RakutenProxy.Model.Rakuten.Mapping
{
    public class ProductMapping : EntityTypeConfiguration<Product>
    {
        public ProductMapping()
        {
            HasKey(t => t.ProductId);

            ToTable("Product");

            Property(t => t.ProductName).IsRequired();
            Property(t => t.Url).IsRequired();
            this.HasRequired(t => t.Currency).WithMany(m => m.Products).HasForeignKey(t => t.CurrencyId);

            this.HasOptional(t => t.Manufacturer).WithMany(m => m.Products).HasForeignKey(t => t.ManufacturerId);

            this.HasRequired(t => t.Category).WithMany(c => c.Products).HasForeignKey(t => t.CategoryId);

            this.HasMany(t => t.ProductAttributeCombinations).WithRequired(p => p.Product).HasForeignKey(p => p.ProductId);

            this.HasMany(t => t.Product_ProductAttribute_Mappings).WithRequired(p => p.Product).HasForeignKey(p => p.ProductId);
        }
    }
}